package com.lindroy.androidplayer.viewmodels

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import androidx.lifecycle.viewModelScope
import androidx.paging.cachedIn
import com.elvishew.xlog.XLog
import com.lindroy.androidplayer.utils.mapSingle
import com.lindroy.androidplayer.logic.network.repository.Repository
import com.lindroy.androidplayer.utils.SingleLiveEvent
import com.lindroy.androidplayer.utils.mapItem

/**
 * @author Lin
 * @date 2022/1/20
 * @function
 */
class ProjectViewModel : PageViewModel() {

    private val _itemClickAction = SingleLiveEvent<ProjectItemViewModel>()

//    private val _collectedLiveData = SingleLiveEvent<Boolean>()

    val itemClickAction = _itemClickAction.mapSingle { it }

    fun getProjectList(cid: Int) = Repository.getProjectList(cid).mapItem {
        ProjectItemViewModel(
            it.id,
            it.link,
            it.chapterName,
            it.author,
            it.title,
            it.desc,
            it.niceDate,
            it.envelopePic,
            SingleLiveEvent<Boolean>(),
            _itemClickAction
        )
    }.cachedIn(viewModelScope)
}